/*
* Copyright (C) 2023 ~ 2033 Ltd.
*
* Author:     helei <2454264168@qq.com>
*
* Maintainer: helei <2454264168@qq.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* General Public License version 3 as published by the Free Software
* Foundation and appearing in the file LICENSE.MIT included in the
* packaging of this file.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef UNAVIGATIONBAR_H
#define UNAVIGATIONBAR_H

#include "uwidget.h"
#include "utkwidgetglobal.h"

#include <QPushButton>

class QHBoxLayout;
class UTKWIDGET_EXPORT UNavigationButton : public QPushButton
{
    Q_OBJECT
public:
    explicit UNavigationButton(const QString text, QWidget* parent = nullptr);
    explicit UNavigationButton(QWidget* parent = nullptr);
    ~UNavigationButton();

    void setCloseButtonMargins(int margins);

    void setButtonType(const ButtonType &type);

    void setBackGroudMargins(const QMargins &margins);

    void init();

    QPainterPath selectPath(const QRect &rect);

signals:
    void closed();

protected:
    void paintEvent(QPaintEvent* event) override;

    void drawBackGroud(QPainter* painter, const QStyleOptionButton* option);

    QPainterPath checkedPath();

    QPainterPath hoverPath();

    QMargins contentMargins = QMargins(0, 0, 0, 0);

    QHBoxLayout* layout = nullptr;
};

class UNavigationBarPrivate;
class UTKWIDGET_EXPORT UNavigationBar : public UWidget
{
    Q_OBJECT
public:
    explicit UNavigationBar(QWidget* parent = nullptr);
    ~UNavigationBar();

    void setAction(const QAction &action);

    void addButton(const QIcon &icon, const QString &text, Qt::Alignment alignment = Qt::AlignLeft | Qt::AlignVCenter);

    void addButton(UNavigationButton* button, Qt::Alignment alignment = Qt::AlignLeft | Qt::AlignVCenter);

    void removeButton(UNavigationButton* button);

signals:
    void addButtonClicked();

    void buttonRemoved(const QString &text);

protected:
    void paintEvent(QPaintEvent* event) override;

private slots:
    void onCloseButton();

private:
    QScopedPointer<UNavigationBarPrivate> d_ptr;
    Q_DISABLE_COPY(UNavigationBar)
    Q_DECLARE_PRIVATE_D(d_ptr, UNavigationBar)
};

#endif // UNAVIGATIONBAR_H
